#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<dirent.h>


int main(int argc, char *argv[]){
    
    if(argc != 3){
        
        printf("输入格式错误\n");
    }

    int dir_fd;
    DIR *dir;
    if((dir = opendir(argv[1])) == NULL){
    
        perror("文件夹打开失败");
    }

    //获取文件夹的fd
    if((dir_fd = dirfd(dir)) < 0 ){
    
        perror("文件指针转换失败!");
        return 0;
    }
    
    int fd = openat(dir_fd,argv[2],O_RDWR|O_CREAT|O_TRUNC,0666);   
    if(fd < 0){
        

        perror("文件打开失败！！");
    }

    char content[] = "你好！！！";
    int w_num;
    if((w_num = write(fd,content,sizeof(content)))<= 0){
        
     perror("文件写入失败！！");   
    }
    close(fd);
    return 0;
}
